package com.junzhiit.nengji.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.bainaeco.framework.base.dao.AbstractBaseDAO;
import com.bainaeco.framework.common.jdbc.StatementParameter;
import com.junzhiit.nengji.bo.FullReductionConditionBO;
import com.junzhiit.nengji.dao.FullReductionConditionDAO;
import com.junzhiit.nengji.model.FullReductionCondition;
import com.junzhiit.nengji.model.enums.Is;

@Repository
public class FullReductionConditionDAOImpl extends AbstractBaseDAO<FullReductionCondition> implements FullReductionConditionDAO {

	@Override
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
	public Boolean deleteByFullReductionId(String fullReductionId) {
		StringBuffer sql=new StringBuffer();
		StatementParameter param=new StatementParameter();
		sql.append("delete from full_reduction_condition where full_reduction_id=?");
		param.setString(fullReductionId);
		return super.updateForBoolean(sql.toString(), param);
	}

	@Override
	public List<FullReductionConditionBO> findByFullReductionId(String fullReductionId) {
		StringBuffer sql=new StringBuffer();
		StatementParameter param=new StatementParameter();
		sql.append("select");
		sql.append(" frc.*");
		sql.append(" from full_reduction_condition frc");
		sql.append(" where frc.is_delete=? and frc.full_reduction_id=? order by frc.level asc");
		param.setInt(Is.NO.toIntValue());
		param.setString(fullReductionId);
		return super.queryForList(sql.toString(), FullReductionConditionBO.class, param);
	}

}
